---------------------------------------------------
---------------------------------------------------
 Can Debt Financing Foster Innovation and Growth?
 Replication Code
 Thomas Geelen, Jakub Hajda, and Erwan Morellec
 Review of Financial Studies
 11-10-2021
---------------------------------------------------
---------------------------------------------------

This document describes the code used to solve the model presented in the paper. For the empirical results (Figure 1 and the data moments) see the folder "data" and the readme file in that folder.

We used Matlab R2021a to run the code and to generate the results. Running the full code can take a significant amount of time (~30 hours).

- The folder "functions model" contains the Matlab files that are used the solve the model.
- The folder "functions results" contains the Matlab files that are used to generate the results presented in the paper.
- The folder "functions other" contains the external Matlab functions that are used.
- The model_settings function sets the parameter values.
- results.m generates the results and the data for graphs and tables presented in the paper; note that there could be tiny differences in the numerical results due to randomness induced by using multiple cores when running the comparative statics.

---------------------------------------------------
 Variables (set in model_settings function)
---------------------------------------------------

oParams.pbar		maximum number of products 
oParams.r           	interest rate
oParams.pi          	tax rate
oParams.n           	maximum number of products a new innovation can generate
oParams.alpha		proportional default cost

bParams.gamma		R&D cost parameters (curvature)
bParams.beta		R&D cost parameters (level)
oParams.H           	entry cost
bParams.xi          	debt issuance costs
bParams.theta		innovation quality
bParams.theta_e		innovation quality entrants
bParams.eta         	fixed operating costs
bParams.f           	rate of creative destruction

oParams.n_e         	maximum number of products entrants
oParams.product_distribution_entrants	product distribution entrants

%% Technical settings

setts.nodebt		1 if no debt case is solved
setts.debt_static	1 if static debt case is solved

setts.equity_in		initial guess equity value
setts.debt_in		initial guess debt value

setts.options		options fmincon
setts.f_max         	maximum value f for binomial search
setts.f_min         	minimum value f for binomial search
setts.f_max_iterations	maximum iterations f search

setts.m             	number of firms simulated
setts.dt			time steps
setts.T0			time after which simulations are used
setts.T             	final time

setts.lambda_grid   	grid lambda
setts.n_lambda     	number of grid points lambda
setts.lambda_max		maximum lambda
setts.lambda_error  	show lambda error (=1)

setts.e_prec        	equity precision
setts.f_prec        	creative destruction precision
setts.d_prec        	debt precisions
	
setts.C             	vector of possible coupon levels, which should include 0

setts.dir           	working directory

---------------------------------------------------
 Functions
---------------------------------------------------

%% /
readme			readme file
model_settings		function that sets the model parameters
results			script that generates the results used in the paper

%% /functions model
debt_update		updates the debt value
debt_value		calculates the debt value
entrant_value		calculates the entrant value
equilibrium		calculates the equilibrium rate of creative destruction
equity_update		updates the equity value
equity_value_coupon 	calculates the equity value for all coupon values
equity_value		calculates the equity value for a single coupon value
moments			solves the model and calculates its moments
OPT                 	function that is used to maximize incumbents R&D policy
OPT_E			function that is used to maximize entrants R&D policy 
q                   	R&D cost function incumbents
q_E                 	R&D cost function entrants
steadystate_distribution	calculates steady state distribution for the static (or no) debt model
updatematrix		calculates the updating matrix used to speed up the calculation of the equity and debt value


%% /functions results
comparative         	performs comparative statics analysis (used in comparative_statics)
comparative_statics 	performs comparative statics analysis
comparative_statics_table		calculate comparative statics table
csMoments           	function used to calculate comparative statics
figures             	code that generates figures
smooth_cs           	code that generates smoothed figures
underinvestment     	function used to calculate level of underinvestment

%% /functions others
binocdf             	binomial distribution's CDF
binopdf             	binomial distribution's PDF
binornd             	binomial distribution's random number generator
ltable              	generates latex tables
nanmean             	average or mean value ignoring NaNs
namsum              	sum value ignoring NaNs
nanvar              	variance ignoring NaNs
os_dir              	function that returns the directory of path1 + path2 correcting for the type of OS
pd_plot             	plot default thresholds
polyfix             	fit polynomial
smooth              	perform windowed smoothing on a vector